ColdFusion Article

Employee Updater: Building a Client-Server Application with Macromedia Flash Data Connection Wizard and ColdFusion


Table of Contents

  1. Introduction
  2. The Back-End ColdFusion Web Service
  3. Preparing Flash
  4. Building the Flash Departments Grid
  5. Creating the Login Screen
  6. Processing Logins
  7. Logging Out
  8. Allowing Insert and Delete
  9. Managing Changes
  10. Processing Updates

Allowing Insert and Delete

Being able to edit data when you are logged in is very useful, but what if you wanted to add a new employee, or delete one? Doing so is actually very easy; here's how you add buttons for those functions:

  1. Select the navLogout form.
  2. Drag a Button component from the Components panel onto the Stage. In the Property inspector, name the instance buttonInsert. Set W=75, H=22, X=20, Y=370. Click the label field and set it to Insert.
  3. Drag another Button component onto the Stage. In the Property inspector, name the instance buttonDelete. Set W=75, H=22, X=100, Y=370. Click the label field and set it to Delete. Your screen should look like Figure 24.

    Placing buttons on a separate Form allows for them to be swapped in and out easily

    Figure 24. Placing buttons on a separate form lets you swap them in and out easily.

  4. Select buttonInsert and enter the following code in the Actions panel:

    // Process insert button
    on (click) {
       // Insert a row into the data set
       _root.application.data.empDataSet.addItem(
          {
             STARTDATE:new Date().getTime(),
             DEPTIDFK:_root.application.data.deptDataSet.DEPARTMENTID
          });
    
    
  5. Select buttonDelete and enter the following code in the Actions panel:

    // Process delete button
    on (click) {
       // Remove current item from data set
       _root.application.data.empDataSet.removeItem();
    }
    
  6. Save your changes and test the application. The user will be able to use the Insert and Delete buttons when he/she logs in to insert and delete employees.

The code that processes inserts uses the DataSet addItem() method to add an employee; it uses the currently selected department id for the department, and today's date as the STARTDATE. The code that processes deletes uses the DataSet removeItem() method to simply remove the currently selected item.

Note that you can enter an employee ID, but the CFC will create one and disregard the one you entered when it writes the information to the database on the server.